import type { RouteRecordRaw } from 'vue-router'

import layout from '@/layout'

const modules: Record<string, RouteRecordRaw[]> = import.meta.glob(
  './modules/*.ts',
  {
    eager: true,
    import: 'default'
  }
)

const routesModules = Object.values(modules).flat()

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Console',
    component: layout,
    redirect: {
      name: 'Cert'
    },
    children: [...routesModules]
  },
  {
    path: '/auth',
    name: 'Auth',
    component: () => import('@/views/auth/AuthView.vue'),
    meta: {
      ignoreAuth: true,
      ignoreKeepAlive: true
    }
  },
  {
    path: '/:pathMatch(.*)',
    meta: {
      ignoreAuth: true,
      ignoreKeepAlive: true
    },
    component: () => import('@/views/modules/notFound')
  }
]

export default routes
